<%@ page import="com.blog.pojo.Articles" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>

<head>
    <title>编辑草稿 - ${articles.title}</title>
    <link rel="icon" href="./favicon/favicon.ico" type="image/x-icon">
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.2/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/bootstrap-icons/1.11.1/font/bootstrap-icons.min.css">
    <script src="js/bootstrap.bundle.min.js"></script>
    <style>
        body{padding-bottom:80px;background:#f8f9fa}
        .fixed-footer{position:fixed;bottom:0;left:0;right:0;background:#fff;border-top:1px solid #dee2e6;padding:1rem;z-index:1030}
        .editor{min-height:300px}
    </style>
</head>
<body>
<div class="container mt-4">
    <!-- 顶部卡片 -->
    <div class="card shadow-sm mb-3">
        <c:forEach items="${articles}" var="article">
        <div class="card-header">
            <h3 class="mb-1">${article.title}</h3>
            <small class="text-muted">作者：${article.userName}　|　创建于：${article.createdAt}</small>
        </div>
    </div>

    <!-- 内容编辑卡片 -->
    <div class="card shadow-sm">
        <div class="card-body">
            <form id="draftForm" action="${pageContext.request.contextPath}/articleServlet?method=saveArticle" method="post">
                <input type="hidden" name="id" value="${article.id}">
                <div class="mb-3">
                    <label class="form-label">标题</label>
                    <input type="text" class="form-control" name="title" value="${article.title}">
                </div>
                <div class="mb-3">
                    <label class="form-label">正文</label>
                    <textarea class="form-control editor" name="content" rows="10">${article.content}</textarea>
                </div>
                <input type="hidden" name="status" id="status">
            </form>
        </div>
    </div>
</div>
</c:forEach>
<!-- 固定底部按钮 -->
<div class="fixed-footer text-center">
    <button class="btn btn-secondary me-2" onclick="history.back()">取消</button>
    <button class="btn btn-warning me-2" onclick="saveDraft(0)">存稿</button>
    <button class="btn btn-primary" onclick="saveDraft(1)">发布</button>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script>
    function saveDraft(status){
        $('#status').val(status);
        $('#draftForm').submit();
    }
</script>
</body>
</html>